package cn.edu.ldu.controller;

import cn.edu.ldu.entity.ChatMemberEntity;
import cn.edu.ldu.entity.GroupChatEntity;
import cn.edu.ldu.entity.UserAccountEntity;
import cn.edu.ldu.protocol.ChatMember;
import cn.edu.ldu.views.main.util.ListModel;

import java.util.ArrayList;
import java.util.List;

public class GroupController {
    private static GroupChatEntity groupChatEntity;
    private static List<GroupChatEntity> groupChatlist;
    private static List<ChatMemberEntity> groupMenberlist;

    /**
     * 将所有分组都添加到一个里面
     * @param groupChatEntity
     * @return
     */
    public static void addGroupList(GroupChatEntity groupChatEntity){
        if (groupChatlist == null)
            groupChatlist = new ArrayList<>();
        groupChatlist.add(groupChatEntity);
    }

    /**
     * 得到好友分组
     */
    public static List<GroupChatEntity> getGroupChatlist(){
        return groupChatlist;
    }

    public static GroupChatEntity getGroupChatEntity(Long groupId){
        for(GroupChatEntity g : groupChatlist){
            if (g.getId().equals(groupId))
                return g;
        }
        return null;
    }

    /**
     * 得到群聊成员
     */
    public static void addGroupmenberList(ChatMemberEntity member){
        if (groupMenberlist == null)
            groupMenberlist = new ArrayList<>();
        groupMenberlist.add(member);
    }

    public static List<ChatMemberEntity> getGroupMenberlist(){
        return groupMenberlist;
    }

    /**
     * 遍历找到群成员对象
     */
    public static ChatMemberEntity getGroupMenber(Long menberId){
        for(ChatMemberEntity uae : groupMenberlist){
            if (uae.getUserId().equals(menberId))
                return uae;
        }
        return null;
    }

}
